package com.company.cloud.web.controller;

import com.company.cloud.web.service.WebArtService;
import com.company.cloud.web.service.WebIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private WebIndexService webIndexService;

    @Autowired
    private WebArtService webArtService;

    @RequestMapping("/create")
    public String create(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "order/create";
    }

    @RequestMapping("/pay")
    public String pay(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "order/pay";
    }


    @RequestMapping("/create2")
    public String create2(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);
        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);

        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "order/create2";
    }

}
